package hairdressing;

import java.util.logging.Level;
import java.util.logging.Logger;

public class Customer extends Thread
{   
    int ID;
        
    @Override
    public void run()
    {
        try
        {
            Hairdressers.max_capacity.acquire();
            Hairdressers.num_of_cust++;
            ID = Hairdressers.num_of_cust;
            Output.Enter(ID);
            
            Hairdressers.waiting_list.add(ID);
            Hairdressers.sofa.acquire();
            Output.Sofa(ID);
            
            Hairdressers.sofa.release();
            Hairdressers.barber_chair.acquire(); 
            Output.Chair(ID);
            
            Hairdressers.Cust_read.release();
            Hairdressers.finished[ID-1].acquire();             
            Hairdressers.barber_chair.release();
            Output.leaveingchair(ID);
            
            Hairdressers.payment.release();
            Hairdressers.receipt.acquire();
            Output.payment(ID);
            
            Hairdressers.max_capacity.release();
            Hairdressers.num_of_exits--;
            Output.Exit(ID);
            System.out.println(Hairdressers.num_of_exits);
        } 
        catch (InterruptedException ex)
        {
            Logger.getLogger(Hairdresser.class.getName()).log(Level.SEVERE, null, ex);
        }
        try
        {
            this.finalize();
        } catch (Throwable ex)
        {
            Logger.getLogger(Customer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
